package org.example.seckill.rabbitmq.seckill;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.example.seckill.config.RabbitMqSeckillConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author woopsion
 * @date 2025-07-05
 */
@Component
@Slf4j
public class SeckillMsgSender {
    @Autowired
    private RabbitTemplate rabbitTemplate;


    public void send_killMsg(Object msg){
        log.info("send_killMsg      发送消息 ====== > " + msg);
        //seckillGoods 封装为String类型的Json 传输
        String jsonStr = JSONUtil.toJsonStr(msg);
        rabbitTemplate
                .convertAndSend(RabbitMqSeckillConfig.EXCHANGE_SECKILL
                        ,"seckill.kill",jsonStr);
    }
}
